<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="p1">
<script type="text/javascript">
        function f() {
            var a=document.getElementById("p1").value.length
            console.log(a)
        }
</script>
<button onclick="f()">获取长度</button>
</body>
</html>